// pages/mine/index.js
Page({
  data: {
    userinfo:{},
    // 被收藏的商品的数量
    collects:0,
    announces:0,
    attentions:0,
    modalHidden:true,
    nickname:"",
    status:"",
    loginflag:0
  },
  showModel:function(){
    var that=this;
    if(that.data.loginflag==0){
      wx.showModal({
        title: '提示',
        
        content: '并没有登录',
        
        success: function(res) {
        if (res.confirm) {
         
        
        } else if (res.cancel) {
        
        
        }
        
        }
        
        })

    }
    else{wx.showModal({
      title: '提示',
      
      content: '是否确认退出',
      
      success: function(res) {
      if (res.confirm) {
        that.handlemodel();
      
      } else if (res.cancel) {
      console.log('用户点击取消')
      
      }
      
      }
      
      })}
  },
  onShow(){
    const userinfo1=wx.getStorageSync("userinfo");
    const status=wx.getStorageSync("authority");
    const flag1=wx.getStorageSync("loginflag");
   
    const nickname=wx.getStorageSync("nickname");
    console.log(flag1)
    console.log(323098954);
    console.log(nickname);
    this.setData({userinfo:userinfo1,nickname:nickname,status:status,loginflag:flag1});
    var loginflag = this.data.loginflag
    console.log(loginflag)
    if(loginflag==0){
		this.setData({userinfo:{}})
	}
    if(loginflag==1){
      const openid=wx.getStorageSync("openid");
      wx.request({
        url: 'http://47.98.133.88:8080/getFollowNum',
        header: {
    
          "Content-Type":
           "applciation/json"
        },
        data: {
         
         
          oid: openid
    
        },
        success: (data1)=> {
          
         this.setData({
          attentions:data1.data
        })
          
        }
        
    
        })
        wx.request({
          url: 'http://47.98.133.88:8080/getCollectNum',
          header: {
      
            "Content-Type":
             "applciation/json"
          },
          data: {
           
           
            oid: openid
      
          },
          success: (data1)=> {
          
            this.setData({
              collects:data1.data
            })
            
          }
          
      
          })
          wx.request({
            url: 'http://47.98.133.88:8080/message/showMessageCount',
            header: {
        
              "Content-Type":
               "applciation/json"
            },
            data: {
             
             
              openId: openid
        
            },
            success: (data1)=> {
             this.setData({
               announces:data1.data
             })
              
              
            }
            
        
            })
       
    }
  },
  onLoad: function (options) {
   
    
  },
  tiaozhuan(){
    console.log(this.data.status)
    if(this.data.status==0){
      const openid=wx.getStorageSync("openid");
      wx.request({
        url: 'http://47.98.133.88:8080/checkAuthentication',
        header: {
    
          "Content-Type":
           "applciation/json"
        },
        data: {
         
         
          oid: openid
    
        },
        success: (data1)=> {
          console.log(data1.data)
         if(data1.data==1){
          wx.navigateTo({
            url:'/pages/xianshi/index?id=0',  //跳转页面的路径，可带参数？隔开，不同参数用 & 分隔；相对路径，不需要.wxml后缀
            
        })
         }else{
          wx.navigateTo({
            url:'/pages/identity/index',  //跳转页面的路径，可带参数？隔开，不同参数用 & 分隔；相对路径，不需要.wxml后缀
            
        })
         }
          
          
        }
        
    
        })

    }else{
      wx.navigateTo({
        url:'/pages/xianshi/index?id=1',  //跳转页面的路径，可带参数？隔开，不同参数用 & 分隔；相对路径，不需要.wxml后缀
        
    })
    }
  },
  handlemodel(){
    console.log("11111");
    this.setData({
      userinfo: {},
      collects:0,
    announces:0,
    attentions:0,
	loginflag:0,
      
    })
    wx.clearStorage();
    this.onLoad();
    
  }
})